//Thu Apr  8 15:21:00 CDT 2010
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

int Pegs = 300;
int Cost = 1000000;

class Shelf
{
public:
	int height;
	int leftEdge;
	int rightEdge;
	int leftpeg;
	int rightpeg;
};
class Position
{
public:
	int NicheX;
	int NicheY;
	int BookX;
	int BookY;
};

bool cmp(Shelf A, Shelf B)
{
	return (A.height < B.height);
}
void Solve(vector<Shelf> v, int k, Position pos)
{
	for (int idx = 0; idx + pos.BookX <= pos.NicheX; idx++)
	{
		int minPegs = 0;
		int minCost = 0;
		if(idx + v[k].rightEdge - v[k].leftEdge < v[k].leftpeg) continue;
		if(v[k].rightpeg + v[k].rightEdge - v[k].leftEdge < idx + pos.BookX) break;
	}
}
int main(int argc, const char* argv[])
{
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
	//Initialization:
	Position NT;
	cin >> NT.NicheX >> NT.NicheY >> NT.BookX >> NT.BookY;
	int N;
	cin >> N;
	vector<Shelf> v(N);
	for (int i = 0; i < N; i++)
	{
		int a, b, c, d, e;
		cin >> a >> b >> c >> d >> e;
		v[i].height = a;
		v[i].leftEdge = b;
		v[i].rightEdge = b + c;
		v[i].leftpeg = b + d;
		v[i].rightpeg = b + e;
	}
	sort(v.begin(), v.end(), cmp);
	//Enumation;
	for (int i = 0; i < N; i++)
	{
		if ((v[i].height + NT.BookY) <= NT.NicheY && (v[i].rightEdge
				- v[i].leftEdge) >= NT.BookX)
		{
			Solve(v, i, NT);
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
/*
 * 11 8 3 4
4
1 1 7 1 4
4 3 7 1 6
7 2 6 3 4
2 0 3 0 3
output:0 0;
11 8 4 6
4
1 1 7 1 4
4 3 7 1 6
7 2 6 3 4
2 0 3 0 3
output:1 3;
*/
